#!/usr/bin/env python

import json
import math

from tornado import httpclient

cli = httpclient.HTTPClient()
res = cli.fetch('https://api.binance.com/api/v1/exchangeInfo')
message = json.loads(res.body)

symbols = {}
for item in message['symbols']:
  key = item['symbol']
  base_currency = item['baseAsset']
  quote_currency = item['quoteAsset']
  tick_size = None
  step_size = None
  for filter in item['filters']:
    if filter['filterType'] == 'PRICE_FILTER':
      tick_size = filter['tickSize']
    if filter['filterType'] == 'LOT_SIZE':
      step_size = filter['stepSize']
  price_precision = -math.log10(float(tick_size))
  qty_precision = -math.log10(float(step_size))
  val = '%d, %d' % (
      price_precision,
      qty_precision,
  )
  symbols[key] = val

for key in sorted(symbols.keys()):
  print('    \'%s\': ProductInfo.gen2(%s),' % (key, symbols[key]))
